/* 
*  Copyright (C) 2009-2010 WCG Project
*
*  This program is free software; you can redistribute it and/or modify it
*  under the terms of the GNU General Public License as published by the
*  Free Software Foundation; either version 2 of the License, or (at
*  your option) any later version.
*
*  This program is distributed in the hope that it will be useful, but
*  WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
*  General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software Foundation,
*  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*  In addition, as a special exception, the author gives permission to
*  link the code of this program with the Half-Life Game Engine ("HL
*  Engine") and Modified Game Libraries ("MODs") developed by Valve,
*  L.L.C ("Valve"). You must obey the GNU General Public License in all
*  respects for all of the code used other than the HL Engine and MODs
*  from Valve. If you modify this file, you may extend this exception
*  to your version of the file, but you are not obligated to do so. If
*  you do not wish to do so, delete this exception statement from your
*  version.
*/



/*
*	CVAR Functions
*/

// Half-Life CVARs
new CVAR_mp_friendlyfire
new CVAR_sv_gravity

// Miscellaneous Configuration CVARs
//new CVAR_query_client
new CVAR_show_player
new CVAR_buy_dead
new CVAR_buy_time
new CVAR_buy_zone
new CVAR_spec_position
new CVAR_grenade_protection
new CVAR_start_level

// Admin CVARs
new CVAR_admin_flag

// XP Saving CVARs
new CVAR_save_pruning
new CVAR_days_before_delete
new CVAR_save_by
new CVAR_save_xp_db

// Database CVARs
new CVAR_sql_dbhost
new CVAR_sql_dbuser
new CVAR_sql_dbpass
new CVAR_sql_dbname
new CVAR_save_end_round

// Items
new CVAR_tome
new CVAR_boots
new CVAR_claw
new CVAR_health
new CVAR_frost
new CVAR_mask
new CVAR_cloak
new CVAR_sock
new CVAR_glove_timer
new CVAR_glove_enh_grenades

// Bot CVARs
new CVAR_bot_quota


public CVAR_Init()
{
	// Plugin Information CVARs

	new szAmxCvar[32]
	formatex( szAmxCvar, 31 , "%s %s", PLUGIN_NAME, PLUGIN_VERSION )

	register_cvar( "Warcraft Generations", PLUGIN_VERSION, FCVAR_SERVER )
	register_cvar( "amx_wcg_version", szAmxCvar, FCVAR_SERVER )
	register_cvar( "amx_wcg_date", PLUGIN_DATE, FCVAR_SERVER )

	// Admin CVARs
	CVAR_admin_flag				= register_cvar( "wcg_admin_flag"			, "m"							)

	// Miscellaneous Configuration CVARs

//	CVAR_query_client			= register_cvar( "wcg_query_client"			, "1"							)
	CVAR_show_player			= register_cvar( "wcg_show_player"			, "1"							)
	CVAR_buy_dead				= register_cvar( "wcg_buy_dead"				, "1"							)
	CVAR_buy_time				= register_cvar( "wcg_buy_time"				, "0"							)
	CVAR_buy_zone				= register_cvar( "wcg_buy_zone"				, "0"							)
	CVAR_spec_position			= register_cvar( "wcg_spec_position"		, "0"							)
	CVAR_grenade_protection		= register_cvar( "wcg_grenade_protection"	, "1"							)
	CVAR_start_level			= register_cvar( "wcg_start_level"			, "0"							)

	// Saving CVARs
	CVAR_save_pruning			= register_cvar( "wcg_save_pruning"			, "0"		, FCVAR_SERVER		)
	CVAR_days_before_delete		= register_cvar( "wcg_days_before_delete"	, "31"							)
	CVAR_save_end_round			= register_cvar( "wcg_save_end_round"		, "1"							)
	CVAR_save_xp_db				= register_cvar( "wcg_save_xp_db"			, "0"							)
	CVAR_save_by				= register_cvar( "wcg_save_by"				, "0"							)

	// Item CVARs
	CVAR_tome					= register_cvar( "wcg_tome"					, "50"							)
	CVAR_boots					= register_cvar( "wcg_boots"				, "0.10"						)
	CVAR_claw					= register_cvar( "wcg_claw"					, "6"							)
	CVAR_health					= register_cvar( "wcg_health"				, "15"							)
	CVAR_frost					= register_cvar( "wcg_frost"				, "125"							)
	CVAR_mask					= register_cvar( "wcg_mask"					, "0.3"							)
	CVAR_cloak					= register_cvar( "wcg_cloak"				, "150"							)
	CVAR_sock					= register_cvar( "wcg_sock"					, "0.5"							)
	CVAR_glove_timer			= register_cvar( "wcg_glove_timer"			, "10"							)
	CVAR_glove_enh_grenades		= register_cvar( "wcg_glove_enh_grenades"	, "0"							)

	// Database CVARs
	CVAR_sql_dbhost				= register_cvar( "wcg_sql_dbhost"			, "127.0.0.1"					)
	CVAR_sql_dbuser				= register_cvar( "wcg_sql_dbuser"			, "root"						)
	CVAR_sql_dbpass				= register_cvar( "wcg_sql_dbpass"			, ""							)
	CVAR_sql_dbname				= register_cvar( "wcg_sql_dbname"			, ""							)

	// Bot CVARs
	CVAR_bot_quota				= get_cvar_pointer( "bot_quota" )
}



// Function will configure the various CVARs
CVAR_Configure()
{
	new iXPDivisor = 5
	set_pcvar_num( CVAR_tome, (get_pcvar_num( CVAR_tome ) / iXPDivisor) )

	// Get Half-Life CVAR Pointers
	CVAR_mp_friendlyfire	= get_cvar_pointer( "mp_friendlyfire" )
	CVAR_sv_gravity			= get_cvar_pointer( "sv_gravity" )
}



public _CVAR_ExecuteConfig()
{
	// Format our config file
	new szConfigFile[64]
	get_configsdir( szConfigFile, 63 )
	add( szConfigFile, 63, "/wcg/wcg.cfg" )

	// Make sure the config file exists!
	if ( file_exists( szConfigFile ) )
		server_cmd( "exec %s", szConfigFile )
	else
	{
		WC3_Log( true, "[ERROR] Config file '%s' missing!", szConfigFile )
		set_fail_state( "Config file is missing, unable to load plugin" )
	}
}